package ro.upt.dcda.web.admin;

import java.util.Map;

import ro.upt.dcda.pricezone.s1.requests.admin.AdminLoginRequest;

import com.opensymphony.xwork2.ActionContext;

public class AdminLoginServlet {

	private String usermail;
	private String password;

	public String execute() throws Exception {
		try {
			AdminLoginRequest loginRequest = new AdminLoginRequest();
			System.out.println("Logging admin.");
			if (loginRequest.work(usermail, password)) {
				System.out.println("Loggin sucessful with adminSid:"
						+ loginRequest.getAdminSid());
				Map<String, Object> session = ActionContext.getContext()
						.getSession();
				session.put("admin", loginRequest.getAdmin());
				session.put("email", loginRequest.getAdmin().getEmail());
				session.put("adminSid", loginRequest.getAdminSid());
				return "success";
			} else {
				return "failed";
			}
		} catch (Exception ex) {
			ex.printStackTrace(System.out);
			return "failed";
		}
	}

	public String getUsermail() {
		return usermail;
	}

	public void setUsermail(String usermail) {
		this.usermail = usermail;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
